** Generating Tables and Plots of
** CCES Confidence Experiment regarding
** Respondents' Views of Threat

*********************
* Stata preliminaries
*********************

clear all

version 14

set more off

* change this to fit your directory structure

global path "~/Dropbox/0001 Academic Projects/Ongoing/0148 The Cyber/Posted/FPA Version/Work"
log using Figure1Log.log, replace
cd "$path/Data/"
use "CCESUsable.dta"

set scheme plotplain

keep threatrussia threatchina threatkorea threatiran newsintadj internethome ///
	age white college female gop7 dem7

*********************
* Analysis
*********************
/*
This section carries out basic OLS regressions as described in the text for 
the four most relevant countries in the threat matrix (excluding Canada and non-
state actors).
*/


* Russia
reg threatrussia i.newsintadj##gop7 i.newsintadj##dem7 i.internethome ///
	age white college female
eststo russia
reg threatchina i.newsintadj##gop7 i.newsintadj##dem7 i.internethome ///
	age white college female
eststo china
reg threatkorea i.newsintadj##gop7 i.newsintadj##dem7 i.internethome ///
	age white college female
eststo korea
reg threatiran i.newsintadj##gop7 i.newsintadj##dem7 i.internethome ///
	age white college female
eststo iran


*********************
* Graphing
*********************
/*
This section produces a chart showing the coefficients that are most relevant
to demonstrating superficial polarization in the responses, one chart per country,
and then combines them.
*/


coefplot china, xline(0) drop(_cons female college age white *.internethome) ///
	name(chinachart) title("China") ///
	nolabels nobaselevels xline(0) ///
	headings(1.newsintadj="{bf:News Interest}" ///
			 1.gop7="{bf:Republican}" ///
			 1.dem7="{bf:Democrat}", labsize(vsmall))  ///
	coeflabels(1.newsintadj = "Only now and then" ///
				2.newsintadj = "Some of the time" ///
				3.newsintadj = "Most of the time" ///
				1.gop7 = "Republican" ///
				1.newsintadj#1.gop7 = "Republican x Only now and then" ///
				2.newsintadj#1.gop7 = "Republican x Some of the time" ///
				3.newsintadj#1.gop7 = "Republican x Most of the time" ///
				1.dem7 = "Democrat" ///
				1.newsintadj#1.dem7 = "Democrat x Only now and then" ///
				2.newsintadj#1.dem7 = "Democrat x Some of the time" ///
				3.newsintadj#1.dem7 = "Democrat x Most of the time") ///
	ylabel(,labsize(tiny))
				

coefplot russia, xline(0) drop(_cons female college age white *.internethome) ///
	name(russiachart) title("Russia") ///
	nolabels nobaselevels xline(0) ///
	headings(1.newsintadj="{bf:News Interest}" ///
			 1.gop7="{bf:Republican}" ///
			 1.dem7="{bf:Democrat}", labsize(vsmall))  ///
	coeflabels(1.newsintadj = "Only now and then" ///
				2.newsintadj = "Some of the time" ///
				3.newsintadj = "Most of the time" ///
				1.gop7 = "Republican" ///
				1.newsintadj#1.gop7 = "Republican x Only now and then" ///
				2.newsintadj#1.gop7 = "Republican x Some of the time" ///
				3.newsintadj#1.gop7 = "Republican x Most of the time" ///
				1.dem7 = "Democrat" ///
				1.newsintadj#1.dem7 = "Democrat x Only now and then" ///
				2.newsintadj#1.dem7 = "Democrat x Some of the time" ///
				3.newsintadj#1.dem7 = "Democrat x Most of the time") ///
	ylabel(,labsize(tiny))
				

coefplot iran, xline(0) drop(_cons female college age white *.internethome) ///
	name(iranchart) title("Iran") ///
	nolabels nobaselevels xline(0) ///
	headings(1.newsintadj="{bf:News Interest}" ///
			 1.gop7="{bf:Republican}" ///
			 1.dem7="{bf:Democrat}", labsize(vsmall))  ///
	coeflabels(1.newsintadj = "Only now and then" ///
				2.newsintadj = "Some of the time" ///
				3.newsintadj = "Most of the time" ///
				1.gop7 = "Republican" ///
				1.newsintadj#1.gop7 = "Republican x Only now and then" ///
				2.newsintadj#1.gop7 = "Republican x Some of the time" ///
				3.newsintadj#1.gop7 = "Republican x Most of the time" ///
				1.dem7 = "Democrat" ///
				1.newsintadj#1.dem7 = "Democrat x Only now and then" ///
				2.newsintadj#1.dem7 = "Democrat x Some of the time" ///
				3.newsintadj#1.dem7 = "Democrat x Most of the time") ///
	ylabel(,labsize(tiny))

coefplot korea, xline(0) drop(_cons female college age white *.internethome) ///
	name(koreachart) title("Korea") ///
	nolabels nobaselevels xline(0) ///
	headings(1.newsintadj="{bf:News Interest}" ///
			 1.gop7="{bf:Republican}" ///
			 1.dem7="{bf:Democrat}", labsize(vsmall))  ///
	coeflabels(1.newsintadj = "Only now and then" ///
				2.newsintadj = "Some of the time" ///
				3.newsintadj = "Most of the time" ///
				1.gop7 = "Republican" ///
				1.newsintadj#1.gop7 = "Republican x Only now and then" ///
				2.newsintadj#1.gop7 = "Republican x Some of the time" ///
				3.newsintadj#1.gop7 = "Republican x Most of the time" ///
				1.dem7 = "Democrat" ///
				1.newsintadj#1.dem7 = "Democrat x Only now and then" ///
				2.newsintadj#1.dem7 = "Democrat x Some of the time" ///
				3.newsintadj#1.dem7 = "Democrat x Most of the time") ///
	ylabel(,labsize(tiny))
	
cd "$path/Charts/"

graph combine russiachart koreachart chinachart iranchart, ycommon xcommon ///
	title("Figure 1: Partisanship and Cyber Threat Perception") ///
	subtitle("Selected OLS Coefficients Displayed", size(small)) ///
	rows(2) xsize(9) ysize(10) ///
	note("Full specification includes demographic controls.",size(vsmall)) ///


graph export "Figure 1.pdf", replace

*********************
* Tables
*********************
/*
This section produces a table with full results from the stored regression results.
*/

cd "$path/Tables/"

cd "~/Dropbox/0001 Academic Projects/Ongoing/0148 The Cyber/Posted/FPA Version/Work/Tables"
esttab russia china iran korea ///
	using TableOLSModels.tex, ///
	label replace nobaselevels ///
	mtitles("Russia" "China" "Iran" "Korea") ///
	title("Partisanship and Cyber Threat Perception") ///
	wrap compress longtable

cd "$path"
log close
